package com.ruoyi.web.controller.screensavetime;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.screensave.domain.ScreenSaveTime;
import com.ruoyi.screensave.service.IScreenSaveService;
import net.sf.jsqlparser.util.validation.metadata.DatabaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
public class screenSaveTimeController {


    @Autowired
    IScreenSaveService iScreenSaveService;

    @PostMapping("/time")
    public AjaxResult setTime(@RequestParam(name = "mins") Integer minutes, @RequestParam(name="showed" )Boolean showed) {
        try {
            System.out.println(minutes);
            System.out.println(showed);
            iScreenSaveService.setScreenSaveTime(minutes, showed);
        } catch (Exception e) {
            return new AjaxResult(500, "服务器出错");
        }
        return new AjaxResult(200, "设置成功");
    }

    @GetMapping("/time")
    public AjaxResult getTime() {
        try {
            ScreenSaveTime screenSaveTime = iScreenSaveService.getScreenSaveTime();
            return new AjaxResult(200, "查询成功", screenSaveTime);

        } catch (IllegalArgumentException e) {
            return new AjaxResult(400, "请先调设置接口");
        } catch (DatabaseException e) {
            return new AjaxResult(500, "内部服务出错，联系管理员");
        }
    }
}
